package com.example.demo.controller;

import com.example.demo.exception.BusinessException;
import com.example.demo.exception.SystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by fangjicai on 2020/6/20.
 */
@RestController
public class DemoController {
    private Logger logger= LoggerFactory.getLogger(DemoController.class);

    @GetMapping("/demo")
    public String demo(){
        logger.warn("demo warn");
        logger.error("demo error");
        return "demo";
    }

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/ex/{num}")
    public void num(@PathVariable int num){
        if(num==0){
            throw  new SystemException("system："+num);
        }else if(num==1){
            throw  new BusinessException("business："+num);
        }
    }

}
